package chapter2;

/**
 * @author ycj
 * @version 1.0
 * @description: TODO
 * @date 2022/5/16
 */

//设计一个requestId生成器
public class Source2_1 {
    public static Source2_1 requestIdCreate=new Source2_1();
    private final int leftBoundary=0;
    private final int rightBoundary=999;
    private int i;

    private Source2_1() {
    }

    public synchronized String nextId(){
        if(i>rightBoundary||i<leftBoundary){
            i=0;
        }else{
            i++;
        }
        return "abcdef"+i;
    }

    public static Source2_1 getRequestIdCreate() {
        return requestIdCreate;
    }
}
